﻿/**
 * 从（x1,y1）--->(x2,y2)绘出箭头（→）,结果坐标分别在全局变量x4,y4,x5,y5
 * @param x1
 * @param y1
 * @param x2
 * @param y2
 */
function traingle(x1,y1,x2,y2){
	var d1=8;
	var d2=5;
	var _hypot_=hypot(x2-x1,y2-y1);

	switch(direction(x1,y1,x2,y2)){
		case 1:
			var x3=x2-d1*(x2-x1)/_hypot_;
			var y3=y2+(d1*(y1-y2)/_hypot_);
			x4=x3-d2*(y1-y2)/_hypot_;
			y4=y3-d2*(x2-x1)/_hypot_;
			x5=x3+d2*(y1-y2)/_hypot_;
			y5=y3+d2*(x2-x1)/_hypot_;
		break;
		case 2:
			var x3=x2+d1*(x1-x2)/_hypot_;
			var y3=y2+d1*(y1-y2)/_hypot_;
			x4=(x3+d2*(y1-y2)/_hypot_);
			y4=(y3-d2*(x1-x2)/_hypot_);
			x5=(x3-d2*(y1-y2)/_hypot_);
			y5=(y3+d2*(x1-x2)/_hypot_);
		break;
		case 3:
			var x3=x2+(d1*(x1-x2)/_hypot_);
			var y3=y2-(d1*(y2-y1)/_hypot_);
			x4=x3-(d2*(y2-y1)/_hypot_);
			y4=y3-d2*(x1-x2)/_hypot_;
			x5=x3+(d2*(y2-y1)/_hypot_);
			y5=y3+d2*(x1-x2)/_hypot_;			
		break;
		case 4:
			var x3=x2-(d1*(x2-x1)/_hypot_);
			var y3=y2-(d1*(y2-y1)/_hypot_);
			x4=x3+d2*(y2-y1)/_hypot_;
			y4=y3-d2*(x2-x1)/_hypot_;
			x5=x3-d2*(y2-y1)/_hypot_;
			y5=y3+d2*(x2-x1)/_hypot_;
		break;
		
	}
}

function hypot(a,b){
	return Math.sqrt(a*a+b*b);
}



function direction(x1,y1,x2,y2){
	if(x2-x1>=0 && y2-y1>=0)
		return 4;
	else if(x2-x1<0 && y2-y1>=0)
		return 3;
	else if(x2-x1<0 && y2-y1<0)
		return 2;
	else 
		return 1;
}